package com.stone.business.zbtz.action;
/**
 * ----装备台账  ACTION---
 */
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import net.sf.json.JSON;
import net.sf.json.JSONSerializer;
import net.sf.json.JsonConfig;

import com.stone.business.zbtz.pojo.TZbtz;
import com.stone.business.zbtz.service.ZbtzService;
import com.stone.para.IConstant;
import com.stone.sys.pojo.TDictionary;
import com.stone.sys.pojo.TOrgan;
import com.stone.sys.pojo.TUser;
import com.stone.sys.service.DictionaryService;
import com.stone.utils.DateFormatTool;
import com.stone.utils.JsonUtils;
import com.stone.utils.StringUtils;

import frm.ssh.action.BaseAction;
import frm.ssh.exception.AppException;
import frm.ssh.util.SpringUtil;

public class ZbtzAction extends BaseAction{
	private ZbtzService zbtzService;
	private TZbtz entity;
	private String id;
	private String hiddenids;
	private List list;
	private String datafrom;
	private String showtype;
	private String directFlag;
	private String cllb;
	private String clmcPram;
	//材料类别
	private List<TDictionary> cllbList;
	//材料名称
	private List<TDictionary> clmcList;
	//材料单位
	private List<TDictionary> cldwList;
	//材料型号
	private List<TDictionary> clxhList;
	//仓库名称
	private List<TDictionary> ckmcList;
	 //班组
	private List<TOrgan> bzList;
	/**
	 * 进入装备台账记录详细页面
	 * 
	 * @return
	 * @throws AppException
	 */
	public String initZbtzDetail() throws AppException {
		
		// 修改进入
		 if (!"0".equals(id.toString())) {
			
			this.entity = (TZbtz) zbtzService.findById(Long.parseLong(id),TZbtz.class.getName());
			

		// 新建进入
		} else {
			
			this.entity = new TZbtz();
			
			 String sysdate = zbtzService.getSysdate("yyyy-MM-dd");
			 this.entity.setStartdate(DateFormatTool.formatToDate(sysdate,false));
			 //this.entity.setEnddate(DateFormatTool.formatToDate(sysdate+" 18:00",true));
			this.entity.setStatus("0");
			this.entity.setDantype(super.getSearchBean().getCon6());
			//this.entity.setOuid(super.getSession().getAttribute(IConstant.SESSION_TORGAN_CODE).toString());
			
			
		}
		
		//初始化材料相关列表 added by cheng 2012-5-21
		initClList();
		if(super.getSearchBean().getCon6().equals("1")){
			return "WJ_SUCCESS";
		}else if(super.getSearchBean().getCon6().equals("2")){
			return "XJ_SUCCESS";
		}else if(super.getSearchBean().getCon6().equals("3")){
			return "DYJ_SUCCESS";
		}else if(super.getSearchBean().getCon6().equals("4")){
			return "GRGQJ_SUCCESS";
		}else {
			return "BZGQJ_SUCCESS";
		}
		/*if(directFlag==null||directFlag.equals("")){
			return "XJ_SUCCESS";
		}else{
			return directFlag;
		}*/
		
	}

	/**
	 * 保存
	 * 
	 * @return
	 * @throws AppException
	 */
	public String saveZbtz() throws AppException {
       String sysdate = zbtzService.getSysdate("YYYY-MM-DD");
       if (entity.getId() == 0) {
    	   this.entity.setStatus("1");
    	   zbtzService.save(entity);		
       }else{
    	   zbtzService.update(entity);
       }
		String forword="";
		/*if(super.getSearchBean().getCon6().equals("2")||"2".equals(this.entity.getDantype())){
			forword="XJ_SUCCESS";
			}else{
				forword="XJ_SUCCESS";
			}*/
		//String rtn = zbtzService.doSave(this.entity, this.clkcmxList);
		super.setInfo("保存成功");
		//初始化班组相关列表 added by wangtao 2013-4-3
		initClList();
		if(super.getSearchBean().getCon6().equals("1")){
			return "WJ_SUCCESS";
		}else if(super.getSearchBean().getCon6().equals("2")){
			return "XJ_SUCCESS";
		}else if(super.getSearchBean().getCon6().equals("3")){
			return "DYJ_SUCCESS";
		}else if(super.getSearchBean().getCon6().equals("4")){
			return "GRGQJ_SUCCESS";
		}else {
			return "BZGQJ_SUCCESS";
		}
		//return forword;

	}
	
	/**
	 * 删除
	 * 
	 * @return
	 * @throws AppException
	 */
	public String deleteZbtz() throws AppException {
		
		zbtzService.doDelAll(id, TZbtz.class.getName());
		
		return "DELETE_SUCCESS";
	}
	
	

	/**
	 * 保存
	 * 
	 * @return
	 * @throws AppException
	 */
	public String save() throws AppException {
		
		String   selectpage=super.getSearchBean().getCon1();
		
		Date confDate = DateFormatTool.formatToDate(zbtzService.getSysdate("yyyy-MM-dd HH24:mi"), true);
		if (this.entity.getId() == 0) {
			
			//this.entity.setOuid(super.getSession().getAttribute(IConstant.SESSION_TORGAN_CODE).toString());
		}
		//String rtn = zbtzService.doSave(this.entity, this.clkcmxList);
		//初始化材料相关列表 added by wangtao 2012-5-22
		initClList();
		//super.setInfo(rtn);

		return SUCCESS;

	}
	
	public void setZbtzService(ZbtzService zbtzService) {
		this.zbtzService = zbtzService;
	}

	public TZbtz getEntity() {
		return entity;
	}

	public void setEntity(TZbtz entity) {
		this.entity = entity;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getHiddenids() {
		return hiddenids;
	}

	public void setHiddenids(String hiddenids) {
		this.hiddenids = hiddenids;
	}
	
	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public String getDatafrom() {
		return datafrom;
	}

	public void setDatafrom(String datafrom) {
		this.datafrom = datafrom;
	}

	public String getShowtype() {
		return showtype;
	}

	public void setShowtype(String showtype) {
		this.showtype = showtype;
	}

	public ZbtzService getZbtzService() {
		return zbtzService;
	}

	

	public String getDirectFlag() {
		return directFlag;
	}

	public void setDirectFlag(String directFlag) {
		this.directFlag = directFlag;
	}

	/**
	 * @return the cllbList
	 */
	public List<TDictionary> getCllbList() {
		return cllbList;
	}

	/**
	 * @param cllbList the cllbList to set
	 */
	public void setCllbList(List<TDictionary> cllbList) {
		this.cllbList = cllbList;
	}

	/**
	 * @return the clmcList
	 */
	public List<TDictionary> getClmcList() {
		return clmcList;
	}

	/**
	 * @param clmcList the clmcList to set
	 */
	public void setClmcList(List<TDictionary> clmcList) {
		this.clmcList = clmcList;
	}

	/**
	 * @return the cldwList
	 */
	public List<TDictionary> getCldwList() {
		return cldwList;
	}

	/**
	 * @param cldwList the cldwList to set
	 */
	public void setCldwList(List<TDictionary> cldwList) {
		this.cldwList = cldwList;
	}

	/**
	 * @return the clxhList
	 */
	public List<TDictionary> getClxhList() {
		return clxhList;
	}

	/**
	 * @param clxhList the clxhList to set
	 */
	public void setClxhList(List<TDictionary> clxhList) {
		this.clxhList = clxhList;
	}

	/**
	 * @return the ckmcList
	 */
	public List<TDictionary> getCkmcList() {
		return ckmcList;
	}

	/**
	 * @param ckmcList the ckmcList to set
	 */
	public void setCkmcList(List<TDictionary> ckmcList) {
		this.ckmcList = ckmcList;
	}

	private void initClList() throws AppException{
		DictionaryService dicService = (DictionaryService) SpringUtil.getInstance().getBean("dicService");
		cllbList = dicService.findList("CLLB");
		clmcList = dicService.findList("CLMC");
		cldwList = dicService.findList("CLDW");
		clxhList = dicService.findList("CLXH");
		ckmcList = dicService.findList("KFMC");
		 //班组
	 	String bzsql = "from TOrgan where id <=24 and id >=21 order by id";
	 	bzList = zbtzService.findListByHql(bzsql);
	}

	public String getCllb() {
		return cllb;
	}

	public void setCllb(String cllb) {
		this.cllb = cllb;
	}


	public String getClmcPram() {
		return clmcPram;
	}

	public void setClmcPram(String clmcPram) {
		this.clmcPram = clmcPram;
	}

	public List<TOrgan> getBzList() {
		return bzList;
	}

	public void setBzList(List<TOrgan> bzList) {
		this.bzList = bzList;
	}

	
}
